<template>
  <view class="login-page">
    <view >
		<image class="logo" src="../../static/login_logo3.jpg" mode=""></image>
	</view>
    <input class="input" placeholder-class="placeholderStyle " type="text" v-model="account" placeholder="请输入用户名" />
    <input class="input" placeholder-class="placeholderStyle " type="password" v-model="password" placeholder="请输入密码" />
    <button class="login-btn" @click="login">登录</button>
	<button class="register-btn" @click="register">注册</button>
	<u-toast ref="loginErr" />
  </view>
</template>

<script>
import {encrypt} from "../../utils/jsencrypt.js" ;
import {baseUrl} from "../../utils/request.js" ;
  export default {
    data() {
      return {
        account: '',
        password: '',
		showErr:false
      }
    },
    methods: {
      login() {
		  uni.request({
		      // url: 'https://www.fastmock.site/mock/68c3c014a443685834fb331ec92e7e9d/show/shop',
			  method:"POST",
		      url: baseUrl+'/mixuebingcheng/user/wxLogin',
			  data:{name:this.account,password:encrypt(this.password)},
		      success: (res) => {
		          console.log(res);
		          // console.log(res.data);
		        if(res.data.data)
				{
					getApp().globalData.userInfo = res.data.data
					uni.switchTab({
						url: '/pages/home/home'
					});
				}
				else
					this.$refs.loginErr.show({
						title: res.data.msg,
						type: 'error',
						
					})
		      }
		  });
       
      },
	  register(){
		  uni.navigateTo({
		  	url: '/pages/register/register'
		  })
	  },
	  showToast() {
	  				this.$refs.loginErr.show({
	  					title: '用户名或密码错误',
	  					type: 'error',
	  					url: '/pages/user/index'
	  				})
	  			}
    }
  }
</script>

<style>
  .login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-color: #e70012;
  }
	.placeholderStyle{
		color: #fff;
	}
  .logo {
    width: 100px;
    height: 100px;
    background-color: #333;
  }

  .input {
    width: 200px;
    height: 40px;
    margin-top: 10px;
    border-radius: 4px;
    padding: 4px;
    border: 1px solid #fff;
	color: #fff;
  }

  .login-btn {
    width: 200px;
    height: 40px;
    margin-top: 20px;
    background-color: #333;
	border: 1px solid #fff;
    color: #fff;
    border-radius: 4px;
  }
  .register-btn {
	border: 1px solid #fff;
	width: 200px;
    height: 40px;
    margin-top: 20px;
    background-color: #f60;
    color: #fff;
    border-radius: 4px;
  }
</style>